<template>
	<div class="login_container">
		<div class="login_box">
			<div class="avatar_box">
				<img src="../assets/logo.png">
			</div>
			<el-form ref="loginFromRef" width="0px" class="login_from" :model="admin" :rules="loginfromrule">
				<el-form-item prop="username">
					<el-input prefix-icon="iconfont icon-user" v-model="admin.username"></el-input>
				</el-form-item>
				<el-form-item prop="password">
					<el-input type="password" prefix-icon="iconfont icon-medicinebox" v-model="admin.password">
					</el-input>
				</el-form-item>
				<el-form-item class="btns">
					<el-button type="primary" @click="login()">注册</el-button>
					<el-button type="infor" @click="resetLoginForm()">重置</el-button>
				</el-form-item>
			</el-form>
		</div>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				admin: {
					username: '',
					password: '',
					type:'stu'
				},
				loginfromrule: {
					username: [{
						required: true,
						message: '请输入用户名',
						trigger: 'blur'
					}],
					password: [{
							required: true,
							message: "请输入密码",
							trigger: 'blur'
						}

					]
				}
			}
		},
		methods: {
			resetLoginForm() {
				this.$refs.loginFromRef.resetFields();
			},
			login() {
				console.log(this.admin);
				
				this.$refs.loginFromRef.validate(valie => {
					if (!valie) return;
					this.$http.post("http://localhost:8989/zhuce",this.admin).then(date => {
						console.log(date.data);
						if (date.data.status !== 200) {
							return this.$message.error('注册失败  请更换用户名');
						} else {
							
								this.$message.success("注册成功 请登录");
								this.$router.push('/login');
							
						}

						// window.sessionStorage.setItem("token",date.data.data.token);
						

					}).catch(err => {
						console.log(err);
					})
				})
			}
		}
	}
</script>

<style scoped>
	.login_container {
		background-color: blanchedalmond;
		height: 100%;
	}

	.login_box {
		width: 450px;
		height: 300px;
		background-color: white;
		border-radius: 3px;
		position: absolute;
		left: 50%;
		top: 50%;
		transform: translate(-50%, -50%);

	}

	.avatar_box {
		height: 130px;
		width: 130px;
		border: 1px solid #272296;
		border-radius: 50%;
		padding: 10px;
		box-shadow: 0 0 10px #ddd;
		position: absolute;
		left: 50%;
		transform: translate(-50%, -50%);
		background-color: #fff;
	}

	img {
		width: 100%;
		height: 100%;
		border-radius: 50%;
		background-color: #DDDDDD;
	}

	.login_from {
		position: absolute;
		bottom: 0;
		width: 100%;
		padding: 0 20px;
		box-sizing: border-box;
	}

	.btns {
		display: flex;
		/* 变成弹性布局 */
		justify-content: flex-end;
	}
</style>
